#pragma once

#include "ZMessageHandler.h"
#include "ZGameMessageCommand.h"
#include <boost/shared_ptr.hpp>
#include <boost/unordered_map.hpp>
#include <boost/bind.hpp>

namespace	Z	{

//------------------------------------------------------------------------------------------------------------------------
class	_ZNetworkApi	GameMessageHandler
	:	public MessageHandler
{
public:
	typedef	boost::shared_ptr<GameMessageCommand>	GameMessageCommandPtr;

public:

	virtual	void	onConnect(NetworkId kNetworkId)	= 0;
	virtual	void	onDisconnect(NetworkId kNetworkId)	= 0;
	virtual	bool	handle(Stream& stream, NetworkId kNetworkId);
protected:
	void	addCommand(GameMessageCommandPtr kCommandPtr);

private:
	typedef	boost::unordered_map<GameMessageId, GameMessageCommandPtr>	GameMessageCommandPtrs;
	GameMessageCommandPtrs	mCommands;
};

}

#define	ON_GAME_MESSAGE(GameMessageT, function, instance)	addCommand(GameMessageCommandPtr(new GameMessageCommandT<GameMessageT>(boost::bind(function, instance, _1))));